/*
 * @Author: luoxi
 * @Date: 2022-01-25 09:51:12
 * @LastEditors: luoxi
 * @LastEditTime: 2022-01-25 12:40:52
 * @FilePath: \vue-admin-box\vite.config.ts
 * @Description:
 */
import {ConfigEnv, UserConfigExport} from 'vite'
import vue                           from '@vitejs/plugin-vue'
import {resolve}                     from 'path'

const pathResolve = (dir: string): any => {
    return resolve(__dirname, ".", dir)
}

const alias: Record<string, string> = {
    '@': pathResolve("src")
}

/**
 * @description-en vite document address
 * @description-cn vite官网
 * https://vitejs.cn/config/ */
export default ({command}: ConfigEnv): UserConfigExport => {
    return {
        base: './',

        resolve: {
            alias
        },

        server: {
            port : 19999, // host : '0.0.0.0',
            open : false,
            proxy: { // 代理配置
                '^/api': {
                    target: 'http://localhost:9999',
                    // target      : 'http://192.168.10.129:9999',
                    changeOrigin: true,
                    ws          : true,
                }
            },
        },

        build: {
            rollupOptions: {
                output: {
                    manualChunks: {
                        'echarts': ['echarts']
                    }
                }
            }
        },

        plugins: [

            vue(),
        ],

        css: {
            postcss: {
                plugins: [
                    {
                        postcssPlugin: 'internal:charset-removal',
                        AtRule       : {
                            charset: (atRule) => {
                                if (atRule.name === 'charset') {
                                    atRule.remove();
                                }
                            }
                        }
                    }
                ],
            },
        }
    };
}
